﻿using Ewelve_Mouth_HD.BLL;
using Ewelve_Mouth_HD.DAL;
using Ewelve_Mouth_HD.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Ewelve_Mouth_HD.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TypeController : ControllerBase
    {
        private readonly TypeBll typeBll;
        private readonly ILogger<TypeController> _logger;

        public TypeController(TypeBll _typeBll, ILogger<TypeController> logger)
        {
            typeBll = _typeBll;
            _logger = logger;
        }
        /// <summary>
        /// 房型添加
        /// </summary>
        /// <param name="E"></param>
        /// <returns></returns>
        [HttpPost]
        public int RoomTypeAdd(RoomType E)
        {
            try
            {
                return typeBll.RoomTypeAdd(E);
            }
            catch (Exception)
            {
                _logger.LogInformation("房型添加错误");
                throw;
            }
        }
        /// <summary>
        /// 房型分页，查询显示
        /// </summary>
        /// <param name="RoomName"></param>
        /// <param name="MaxArea"></param>
        /// <param name="MinArea"></param>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="PageSum"></param>
        /// <param name="PageCount"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult TypeShowAll(string? RoomName, int MaxArea, int MinArea, int PageIndex, int PageSize)
        {
            int PageSum = 0;
            int PageCount = 0;
            var list= typeBll.TypeShowAll(RoomName, MaxArea, MinArea, PageIndex, PageSize, out PageSum, out PageCount);
            return Ok(new { PageSum= PageSum, PageCount= PageCount, list = list });
        }
        /// <summary>
        /// 绑定下拉框
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IQueryable SelectShow()
        {
            _logger.LogInformation("房型显示错误");
            return typeBll.SelectShow();
        }
    }
}
